<!--
 * @Author: H.
 * @Date: 2021-12-06 18:12:03
 * @LastEditTime: 2021-12-14 13:14:47
 * @Description:
-->
<template>
  <div class="goods">
    <page-search
      :searchFormConfig="searchFormConfig"
      @queryBtnClick="handleQueryClick"
      @resetBtnClick="handleResetClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      pageName="goods"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    >
      <template #imgUrl="scope">
        <el-image
          style="width: 60px; height: 60px"
          :src="scope.row.imgUrl"
          :preview-src-list="[scope.row.imgUrl]"
          :initial-index="1"
        >
        </el-image>
      </template>
      <template #status="scope">
        <el-tag size="mini" :type="scope.row.status ? 'success' : 'danger'">{{
          scope.row.status ? '可用' : '下架'
        }}</el-tag>
      </template>
    </page-content>
    <page-modal
      ref="pageModalRef"
      :defaultInfo="defaultInfo"
      :pageModalConfig="modalConfig"
      pageName="goods"
      :pageModalTitle="pageModalTitle"
    ></page-modal>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'
import PageModal from '@/components/page-modal'

import { usePageSearch } from '@/hooks/usePageSearch'
import { usePageModal } from '@/hooks/usePageModal'

import { searchFormConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

export default defineComponent({
  name: 'goods',
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()
    const editCallback = () => {
      pageModalTitle.value = '编辑商品'
    }
    const newCallback = () => {
      pageModalTitle.value = '新增商品'
    }
    const pageModalTitle = ref('新增商品')

    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)
    return {
      contentTableConfig,
      searchFormConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfig,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData,
      pageModalTitle
    }
  },
  components: {
    PageContent,
    PageSearch,
    PageModal
  }
})
</script>

<style scoped></style>
